/*
 * searchVip.java
 *
 * Created on __DATE__, __TIME__
 */

package com.shangpintechnology.sci;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableModel;

/**
 *
 * @author  __USER__
 */
public class SearchVip extends javax.swing.JDialog {

	/** Creates new form searchVip */
	public SearchVip(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		vipInfoTable = new javax.swing.JTable();
		close = new javax.swing.JButton();
		handOutCard = new javax.swing.JButton();
		jButtonDel = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setLocationByPlatform(true);

		vipInfoTable.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null, null },
						{ null, null, null, null }, { null, null, null, null },
						{ null, null, null, null } }, new String[] { "Title 1",
						"Title 2", "Title 3", "Title 4" }));
		jScrollPane1.setViewportView(vipInfoTable);

		close.setText("\u5173\u95ed");
		close.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				closeActionPerformed(evt);
			}
		});

		handOutCard.setText("\u53d1\u5361");

		jButtonDel.setText("\u5220\u9664");
		jButtonDel.setToolTipText("\u5220\u9664\u9009\u4e2d\u7528\u6237");
		jButtonDel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButtonDelActionPerformed(evt);
			}
		});

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								layout
										.createSequentialGroup()
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																layout
																		.createSequentialGroup()
																		.addContainerGap()
																		.add(
																				jScrollPane1,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				594,
																				Short.MAX_VALUE))
														.add(
																layout
																		.createSequentialGroup()
																		.add(
																				216,
																				216,
																				216)
																		.add(
																				close)
																		.add(
																				39,
																				39,
																				39)
																		.add(
																				handOutCard)
																		.add(
																				18,
																				18,
																				18)
																		.add(
																				jButtonDel)))
										.addContainerGap()));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								layout
										.createSequentialGroup()
										.add(
												jScrollPane1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												264,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(close).add(
																handOutCard)
														.add(jButtonDel))
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void jButtonDelActionPerformed(java.awt.event.ActionEvent evt) {
		int row= vipInfoTable.getSelectedRow();
		if(row<0){
			JOptionPane.showMessageDialog(null, "请先选择需要删除的行");
		}else{
			TableModel model = vipInfoTable.getModel();
			String id =(String) model.getValueAt(row, 0);
			if(null==id||""==(String)id){
				JOptionPane.showMessageDialog(null, "数据错误");
			}else{
				DAO dao = new DAO();
				dao.removeCustomer(id);
				JOptionPane.showMessageDialog(null, "删除成功");
				dispose();
			}
		}
		
		
	}

	private void closeActionPerformed(java.awt.event.ActionEvent evt) {
		this.removeAll();
		this.setVisible(false);
	}

	public javax.swing.JButton getClose() {
		return close;
	}

	public void setClose(javax.swing.JButton close) {
		this.close = close;
	}

	public javax.swing.JTable getVipInfoTable() {
		return vipInfoTable;
	}

	public void setVipInfoTable(javax.swing.JTable vipInfoTable) {
		this.vipInfoTable = vipInfoTable;
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				SearchVip dialog = new SearchVip(new javax.swing.JFrame(), true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton close;
	private javax.swing.JButton handOutCard;
	private javax.swing.JButton jButtonDel;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable vipInfoTable;

	// End of variables declaration//GEN-END:variables
	public JButton getHandOutCard() {
		// TODO Auto-generated method stub
		return handOutCard;
	}

}